<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/html/head :: head(~{::title},~{::link},~{::style})">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>更新单文件</title>
<!-- 文件上传css-->
<link th:href="@{/static/assets/dropZone/downloads/css/dropzone.css}" rel="stylesheet"/>
<link th:href="@{/static/assets/zTree_v3/css/zTreeStyle/zTreeStyle.css}" rel="stylesheet"/>

<style type="text/css">
ul {
	
}
#div1{
float: left;
    width: 50%;
    height: 300px;
}
#div2{
	float: left;
    width: 50%;
    height: 300px;
}
</style>
</head>
<body>
<div>
	<div  id="div1">
			<ul id="treeDemo" class="ztree"></ul>
	</div>
	
	<div id="div2"><div id="dropz"  class="dropzone"></div></div>
</div>


<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js">
</div>
<!--文件上传dropzone.js -->
<script th:src="@{/static/assets/dropZone/lib/dropzone.js}" type="text/javascript"></script>


<script th:src="@{/static/assets/zTree_v3/js/jquery.ztree.core.min.js}" type="text/javascript"></script>

<script type="text/javascript" th:inline="javascript">
var myDropzone;
$(function(){
    var tomcatName = localStorage.getItem("tomcatName");
	Dropzone.autoDiscover = false;//防止报"Dropzone already attached."的错误
	 myDropzone = new Dropzone("#dropz", {
	       url: rootPath + "/TomcatController/updateFiles",//文件提交地址
	       headers:{"a":11},
	       method:"post",  //也可用put
	       paramName:"file", //默认为file
	       maxFiles:1,//一次性上传的文件数量上限
	       maxFilesize: 1000, //文件大小，单位：MB
	       acceptedFiles: ".zip,.class,.html", //上传的类型
	       addRemoveLinks:true,
	       parallelUploads: 1,//一次上传的文件数量
	       //previewsContainer:"#preview",//上传图片的预览窗口
	       dictDefaultMessage:'拖动文件至此或者点击上传',
	       dictMaxFilesExceeded: "您最多只能上传1个文件！",
	       dictResponseError: '文件上传失败!',
	       dictInvalidFileType: "文件类型只能是*.jpg,*.gif,*.png,*.jpeg。",
	       dictFallbackMessage:"浏览器不受支持!",
	       dictFileTooBig:"文件过大上传文件最大支持.",
	       dictRemoveLinks: "删除",
	       dictCancelUpload: "取消",
	       init:function(){
	           this.on("addedfile", function(file) {
	               //上传文件时触发的事件

	           });
	           this.on("success",function(file,data){
	               alert(data.msg);
                   $.modal.close();
	           });
	           this.on("error",function (file,data) {
	               //上传失败触发的事件
	        	   $.modal.alertError("上传失败！");
	           });
	           this.on("removedfile",function(file){//删除文件触发结果



	           });
	       }
	});
	
	<!--tree-->
	

	

})





$(function(){
	var tomcatName = localStorage.getItem("tomcatName");
	var projectUrl = localStorage.getItem("projectUrl");
	$.ajax({
		type : "get",
		url : rootPath + "/TomcatController/getDirAndFilePath/"+projectUrl+"/"+tomcatName,
		contentType: "application/json",//设置请求参数类型为json字符串
		dataType:"json",
		error : function(request) {
			$.modal.alertError("系统错误");
		},
		success:function(data){
			packNodes(data);
		}
	});
	
})

 var zTreeObj;
	function packNodes(data){
		var setting = {
				callback:{
					onClick:function(){
						myDropzone.options.headers={
							url:getParentNames(),
							projectUrl:encodeURI(localStorage.getItem("projectUrl")),
							tomcatName:encodeURI(localStorage.getItem("tomcatName"))
						};
					}
				}
		};
		var zNodes =""
        zNodes = data.data;
		$(document).ready(function(){
			  zTreeObj=$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		});
	}


	function fzData(data){
        var nodeArr = new Array();
        for(var i = 0;i<data.length;i++){
            data[i];
        }

    }
	
	/**
	*获取父节点标签
	*/
	function getParentNames(){
		var localosturl=[];
		var treeObj = zTreeObj;
		var sNodes = treeObj.getSelectedNodes();
		if (sNodes.length > 0) {
			var node = sNodes[0].getPath();
			for (var i = 0; i < node.length; i++) {
				var lement = node[i];
				if(lement!=null){
					localosturl.push(lement.name);
				}
			}
			
		}
		return localosturl.join("\\");
	}

</script>
</body>
</html>